/*     */ package com.infoservice.schedule.generator;
/*     */ 
/*     */ import com.infoservice.po3.POFactory;
/*     */ import com.infoservice.po3.POFactoryBuilder;
/*     */ import com.infoservice.po3.core.context.POContext;
/*     */ import com.infoservice.po3.core.exceptions.DAOException;
/*     */ import com.infoservice.schedule.po.pos.TaskPO;
/*     */ import com.infoservice.schedule.util.TaskUtils;
/*     */ import java.sql.SQLException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Date;
/*     */ import java.util.LinkedList;
/*     */ import java.util.List;
/*     */ import java.util.TimerTask;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public abstract class TaskGenerator extends TimerTask
/*     */ {
/*  40 */   public Logger logger = Logger.getLogger(TaskGenerator.class);
/*     */ 
/*  42 */   protected TaskPlanInfo tpInfo = null;
/*  43 */   protected TaskPO tk = null;
/*     */ 
/*     */   public TaskGenerator(TaskPlanInfo tpInfo, TaskPO tk) {
/*  46 */     this.tpInfo = tpInfo;
/*  47 */     this.tk = tk;
/*     */   }
/*     */ 
/*     */   public void genTask() {
/*     */     try {
/*  52 */       Date planStartTime = getNextExcTime();
/*  53 */       if (!TaskUtils.checkTimeRange(planStartTime, this.tpInfo.getPlanStart(), this.tpInfo.getPlanEnd()))
/*  54 */         return;
/*     */       Date planStartTime;
/*  56 */       POFactory factory = POFactoryBuilder.getInstance();
/*  57 */       TaskPO taskpo = new TaskPO();
/*  58 */       taskpo.setTaskId(this.tpInfo.getTaskId());
/*  59 */       taskpo.setPlanId(this.tpInfo.getPlanId());
/*  60 */       taskpo.setIgnoreFlag(this.tpInfo.getPlanIgnoreFlag());
/*  61 */       taskpo.setMarker(Integer.valueOf(0));
/*  62 */       taskpo.setExecuteType(this.tpInfo.getTaskManual());
/*  63 */       taskpo.setRunType(this.tpInfo.getPlanRunType());
/*  64 */       taskpo.setStartTimeout(this.tpInfo.getPlanStartTimeout());
/*  65 */       taskpo.setP1value(this.tpInfo.getP1value());
/*  66 */       taskpo.setP2value(this.tpInfo.getP2value());
/*  67 */       taskpo.setP3value(this.tpInfo.getP3value());
/*  68 */       taskpo.setP4value(this.tpInfo.getP4value());
/*  69 */       taskpo.setP5value(this.tpInfo.getP5value());
/*  70 */       taskpo.setLogId(factory.getLongPK(taskpo));
/*  71 */       taskpo.setLogId(factory.getLongPK(taskpo));
/*  72 */       taskpo.setPlanStartTime(planStartTime);
/*  73 */       factory.insert(taskpo);
/*  74 */       POContext.endTxn(true);
/*  75 */       this.logger.info("任务编号==" + this.tpInfo.getTaskId() + "，计划编号===" + this.tpInfo.getPlanId() + "，类型===" + this.tpInfo.getPlanRepeatType() + "，计划执行时间===" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(planStartTime));
/*  76 */       setTaskPO(planStartTime);
/*     */     } catch (DAOException e) {
/*  78 */       if ((e.getCause() instanceof SQLException)) {
/*  79 */         SQLException sqlE = (SQLException)e.getCause();
/*  80 */         if ((sqlE.getErrorCode() == 1) && (sqlE.getMessage().indexOf("ORA-00001") != -1)) {
/*  81 */           this.logger.error(e.getMessage(), e);
/*     */         }
/*     */       }
/*  84 */       POContext.endTxn(false);
/*     */     } catch (Exception e) {
/*  86 */       this.logger.error(e.getMessage(), e);
/*  87 */       POContext.endTxn(false);
/*     */     } finally {
/*  89 */       POContext.cleanTxn();
/*     */     }
/*     */   }
/*     */ 
/*     */   public abstract Date getNextExcTime();
/*     */ 
/*     */   public abstract long getDelayTime();
/*     */ 
/*     */   public abstract long getPeriodTime();
/*     */ 
/*     */   public void fixTask()
/*     */   {
/* 108 */     if (this.tpInfo.getPlanIgnoreFlag().intValue() == 1) {
/* 109 */       int times = getIgnoreTimes();
/* 110 */       if (times <= 0) {
/* 111 */         return;
/*     */       }
/*     */       try
/*     */       {
/* 115 */         POFactory factory = POFactoryBuilder.getInstance();
/* 116 */         TaskPO taskpo = null;
/* 117 */         Date planStartTime = null;
/* 118 */         List ret = new LinkedList();
/* 119 */         if (this.tk == null)
/* 120 */           planStartTime = getStartDate();
/*     */         else {
/* 122 */           planStartTime = this.tk.getPlanStartTime();
/*     */         }
/* 124 */         Date date = null;
/* 125 */         for (int i = 1; i <= times; i++) {
/* 126 */           if (this.tk == null)
/* 127 */             date = planStartTime;
/*     */           else {
/* 129 */             date = new Date(planStartTime.getTime() + i * getInterval());
/*     */           }
/*     */ 
/* 133 */           if ((this.tpInfo.getPlanRunType().intValue() == 1) && (!TaskUtils.checkTimeRange(date, this.tpInfo.getPlanStart(), this.tpInfo.getPlanEnd()))) {
/*     */             continue;
/*     */           }
/* 136 */           taskpo = new TaskPO();
/* 137 */           taskpo.setTaskId(this.tpInfo.getTaskId());
/* 138 */           taskpo.setPlanId(this.tpInfo.getPlanId());
/* 139 */           taskpo.setIgnoreFlag(this.tpInfo.getPlanIgnoreFlag());
/* 140 */           taskpo.setMarker(Integer.valueOf(0));
/* 141 */           taskpo.setExecuteType(this.tpInfo.getTaskManual());
/* 142 */           taskpo.setRunType(this.tpInfo.getPlanRunType());
/* 143 */           taskpo.setStartTimeout(this.tpInfo.getPlanStartTimeout());
/* 144 */           taskpo.setP1value(this.tpInfo.getP1value());
/* 145 */           taskpo.setP2value(this.tpInfo.getP2value());
/* 146 */           taskpo.setP3value(this.tpInfo.getP3value());
/* 147 */           taskpo.setP4value(this.tpInfo.getP4value());
/* 148 */           taskpo.setP5value(this.tpInfo.getP5value());
/* 149 */           taskpo.setLogId(factory.getLongPK(taskpo));
/* 150 */           taskpo.setPlanStartTime(date);
/* 151 */           this.logger.info("任务编号==" + this.tpInfo.getTaskId() + "，计划编号===" + this.tpInfo.getPlanId() + "，类型===" + this.tpInfo.getPlanRepeatType() + "，计划执行时间===" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(planStartTime));
/* 152 */           ret.add(taskpo);
/*     */         }
/* 154 */         factory.insert(ret);
/* 155 */         POContext.endTxn(true);
/* 156 */         if (ret.size() > 0)
/* 157 */           setTaskPO(((TaskPO)ret.get(times - 1)).getPlanStartTime());
/*     */       } catch (Throwable t) {
/* 159 */         this.logger.error(t.getMessage(), t);
/* 160 */         POContext.endTxn(false);
/*     */       } finally {
/* 162 */         POContext.cleanTxn();
/*     */       }
/*     */     }
/*     */     else {
/* 166 */       return;
/*     */     }
/*     */   }
/*     */ 
/*     */   public abstract long getInterval();
/*     */ 
/*     */   public abstract Date getStartDate();
/*     */ 
/*     */   public abstract void setTaskPO(Date paramDate);
/*     */ 
/*     */   public abstract int getIgnoreTimes();
/*     */ 
/*     */   public void removeTaskPlan() {
/* 183 */     cancel();
/*     */   }
/*     */ 
/*     */   public abstract Date getEndDate();
/*     */ }

/* Location:           D:\Workspace\Work\ASMP_DE\lib\frame3\InfoSchedule_1.0.03.jar
 * Qualified Name:     com.infoservice.schedule.generator.TaskGenerator
 * JD-Core Version:    0.6.0
 */